<template>
  <div>
    <el-table v-loading="loading" :data="dataSource" @row-click="handleRowClick" border stripe :height="autoHeight">
      <el-table-column label="操作" align="center" width="100px">
        <div slot-scope="scope">
          <el-button type="success" icon="el-icon-s-custom" circle @click="handleTodo(scope.row, scope.$index)" title="处理"></el-button>
        </div>
      </el-table-column>
      <el-table-column prop="mainName" label="启动业务" align="center">
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="todoDescribe" label="任务描述" align="center">
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="processLabel" label="流程类型" align="center">
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="processName" label="业务流程" align="center">
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="activityName" label="业务节点" align="center">
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
      </el-table-column>
      <el-table-column v-if="activityState !== 'ready'" prop="updateByName" label="发送人" align="center">
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="updateAt" label="更新日期" align="center" width="150px"></el-table-column>
      <el-table-column v-if="activityState === 'finish'" prop="taskTime" label="任务用时(小时)" align="center" width="150px"></el-table-column>
    </el-table>
    <div class="lab-table-page">
      <div style="display: inline-flex">
        <el-pagination
            :disabled="loading"
            :current-page="pageInfo.page"
            :page-sizes="[5, 10, 15, 20, 50, 100]"
            :page-size="pageInfo.pageSize"
            layout="total, sizes, jumper"
            :total="pageInfo.total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
        />
        <el-button-group style="padding: 2px 5px">
          <el-button icon="el-icon-refresh" title="刷新" :disabled="loading" @click="loadSource([])" />
        </el-button-group>
      </div>
    </div>
  </div>
</template>

<script>
import IdeaTable from "@/mixins/IdeaTable";

export default {
  name: "TodoTable",
  mixins: [IdeaTable],
  props: {
    activityState: {
      type: String,
      default: 'runing'
    }
  },
  created() {
    this.queryUrl = '/process/todos'
    this.rowKey = 'todoId'
    const { jobs, roles, userId, branchId, groupId } = this.loginUser
    this.$set(this.pageInfo, 'userId', userId)
    this.$set(this.pageInfo, 'branchId', branchId)
    this.$set(this.pageInfo, 'groupId', groupId)
    this.$set(this.pageInfo, 'roles', roles || [])
    this.$set(this.pageInfo, 'roles', roles || [])
    this.addFilter({ field: 'activityState', op: '=', value: this.activityState })
    this.loadSource()
  },
  computed: {
    autoHeight() {
      return `calc(100vh - 185px)`
    }
  },
  methods: {
    handleTodo(row, index) {
      const { todoId, activityView, activityName, processDefId,mainValue, mainName, appId } = row
      if (!activityView) {
        this.$resultMsg(this, { msg: '该待办不能处理'})
        return
      }
      this.$router.push({
        name: 'TodoView',
        query: {
          title: `${mainName || mainValue}(${activityName})`
        },
        params: {
          appId: appId,
          todoId: todoId,
          mainValue: mainValue,
          processDefId: processDefId
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
